package yto.freemarker.grafana_prometheus_boot.api;

import lombok.*;

/**统一响应的api
 * @author dongxing
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ToString
public class Result {
    private int code;
    private String msg;
    private Object data;

    public static Result instance(ResultType resultType) {
        return Result.builder().code(resultType.code).msg(resultType.msg).build();
    }

    public static Result instance(ResultType resultType, Object o) {
        return Result.builder().code(resultType.code).msg(resultType.msg).data(o).build();
    }

    public enum ResultType {
        success(100, "success"),
        fail(200, "fail");
        private int code;
        private String msg;

        ResultType(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }
}
